package com.zjitc.book.common.exception;

import cn.hutool.http.HttpStatus;
import com.zjitc.book.common.result.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;
@Slf4j
@RestController
public class GlobalExceptionHandle {

    // 异常捕获
    @ExceptionHandler(Exception.class)
    public R<String> handleException(Exception e){
        log.warn("{}-{}",e.getMessage(),(e.getCause()==null?"未知":e.getCause()));
        return R.error(HttpStatus.HTTP_INTERNAL_ERROR,e.getMessage());
    }
}
